package com.thinkgem.jeesite.modules.devmng.web;

import com.thinkgem.jeesite.common.annotation.MobileApi;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseMessage;
import com.thinkgem.jeesite.common.web.BaseMobileApiController;
import com.thinkgem.jeesite.modules.devmng.entity.TaskMain;
import com.thinkgem.jeesite.modules.devmng.service.TaskMainService;
import com.thinkgem.jeesite.modules.devmng.vo.*;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.MobileUserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * Created by admin on 2017-12-5.
 */
@MobileApi
@RestController
@RequestMapping("/mobile-api/taskMain")
public class TaskMainMobileController extends BaseMobileApiController {

    @Autowired
    private TaskMainService taskMainService;

    @RequestMapping(value = "/sign")
    @ResponseStatus(value = HttpStatus.OK)
    public BaseMessage sign(@RequestBody TaskMainSignRequest taskMainSignRequest) {
        taskMainService.sign(taskMainSignRequest);
        return BaseMessage.getDefaultSuccessMessage();
    }

    @RequestMapping(value = "/applyForDelay")
    public BaseMessage applyForDelay(@RequestBody ApplyForDelayRequest applyForDelayRequest) {
        taskMainService.applyForDelay(applyForDelayRequest);
        return BaseMessage.getDefaultSuccessMessage();
    }

    @RequestMapping(value = "/access")
    public BaseMessage access(@RequestBody TaskMainAccessRequest taskMainAccessRequest) {
        taskMainService.access(taskMainAccessRequest);
        return BaseMessage.getDefaultSuccessMessage();
    }

    @RequestMapping(value = "/findTaskList", method = RequestMethod.POST)
    public Page<TaskMain> findTaskList(@RequestBody ListTaskMainRequest request) {
        User user = MobileUserContext.get();
        Page<TaskMain> page = new Page();
        page.setPageNo(request.getPageNo());
        page.setPageSize(request.getPageSize());
        TaskMain taskMain = new TaskMain();
        if (StringUtils.isNotBlank(request.getTaskStatus())) {
            taskMain.setTaskStatus(request.getTaskStatus());
        }
        if (StringUtils.isNotBlank(request.getTaskType())) {
            taskMain.setTaskType(request.getTaskType());
        }
        taskMain.setTaskOperator(user);
        return taskMainService.findPage(page, taskMain);
    }

    @RequestMapping(value = "/getTaskMain")
    public TaskMainResponse getTaskMain(@RequestParam("taskMainId") String taskMainId) {
        return taskMainService.getTaskMainResponse(taskMainId);
    }


}
